Skip to content

Conversation

@kamilkisiela
Copy link
Contributor

@kamilkisiela kamilkisiela commented Jan 5, 2026

This PR significantly improves JSON response serialization (response projection) performance (50% faster) by replacing the existing character-by-character string escaping logic with a SIMD-accelerated implementation adapted from sonic-rs.

I also improved estimate_final_response_size() with 20% buffer for JSON overhead, that according to the tests I did and responses in the federation audit, is a good estimate.

This code is complex and challenging to maintain, due to the low-level SIMD operations, unsafe pointer manipulation, and platform-specific optimizations. However, the previous implementation was also difficult to maintain in its own way.

The key advantage here is that we're leveraging battle-tested code from sonic-rs, a library we already depend on indirectly.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kamilkisiela, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request overhauls the internal mechanism for writing and escaping JSON strings, adopting a high-performance, SIMD-optimized solution. The goal is to boost the efficiency of JSON serialization within the executor. Additionally, it refines the estimation of final response sizes to better reflect the actual memory footprint after JSON formatting.

Highlights

  • Refactored JSON String Escaping: The core logic for writing and escaping JSON strings has been completely rewritten, moving from a custom implementation to a highly optimized, SIMD-accelerated approach inspired by the cloudwego/sonic-rs project. This change is expected to significantly improve performance for JSON serialization.
  • New Dependency: sonic-simd: The sonic-simd crate has been introduced and integrated to provide the underlying SIMD capabilities for the new string escaping logic, enhancing efficiency by processing multiple bytes simultaneously.
  • Improved Response Size Estimation: The estimate_final_response_size function now includes a 20% buffer in its calculation. This buffer accounts for the additional overhead introduced by JSON syntax, character escaping, and other formatting, leading to more accurate size predictions.
  • Enhanced Test Coverage: New test cases have been added for the format_string function, thoroughly validating the correctness of the updated JSON string quoting and escaping logic, including scenarios with special characters and long strings.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant performance improvement by replacing the existing JSON string escaping logic with a SIMD-accelerated implementation from sonic-rs. While the performance gain is valuable, the new code introduces a large amount of unsafe Rust. My review focuses on ensuring this new code adheres to the project's style guide, particularly regarding safety, and improving the maintainability of the new tests and heuristics.

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

k6-benchmark results

     ✓ response code was 200
     ✓ no graphql errors
     ✓ valid response structure

     █ setup

     checks.........................: 100.00% ✓ 207636      ✗ 0    
     data_received..................: 6.1 GB  201 MB/s
     data_sent......................: 81 MB   2.7 MB/s
     http_req_blocked...............: avg=3.21µs   min=662ns   med=1.72µs  max=12.47ms  p(90)=2.58µs  p(95)=3.06µs  
     http_req_connecting............: avg=535ns    min=0s      med=0s      max=1.88ms   p(90)=0s      p(95)=0s      
     http_req_duration..............: avg=21.19ms  min=2.28ms  med=20.18ms max=137.92ms p(90)=28.93ms p(95)=32.23ms 
       { expected_response:true }...: avg=21.19ms  min=2.28ms  med=20.18ms max=137.92ms p(90)=28.93ms p(95)=32.23ms 
     http_req_failed................: 0.00%   ✓ 0           ✗ 69232
     http_req_receiving.............: avg=146.19µs min=26.77µs med=41.51µs max=41.01ms  p(90)=94.84µs p(95)=431.82µs
     http_req_sending...............: avg=23.72µs  min=6.06µs  med=11.16µs max=24.24ms  p(90)=17.59µs p(95)=28.63µs 
     http_req_tls_handshaking.......: avg=0s       min=0s      med=0s      max=0s       p(90)=0s      p(95)=0s      
     http_req_waiting...............: avg=21.02ms  min=2.21ms  med=20.04ms max=125.84ms p(90)=28.68ms p(95)=31.91ms 
     http_reqs......................: 69232   2302.38432/s
     iteration_duration.............: avg=21.67ms  min=4.54ms  med=20.54ms max=249.46ms p(90)=29.41ms p(95)=32.81ms 
     iterations.....................: 69212   2301.719199/s
     vus............................: 50      min=50        max=50 
     vus_max........................: 50      min=50        max=50 

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

🐋 This PR was built and pushed to the following Docker images:

Image Names: ghcr.io/graphql-hive/router

Platforms: linux/amd64,linux/arm64

Image Tags: ghcr.io/graphql-hive/router:pr-638 ghcr.io/graphql-hive/router:sha-7d1c151

Docker metadata
{
"buildx.build.ref": "builder-2591cfbc-35be-4579-997d-230489ec460b/builder-2591cfbc-35be-4579-997d-230489ec460b0/w0tmheh6puivyio2dxm9fdsy3",
"containerimage.descriptor": {
  "mediaType": "application/vnd.oci.image.index.v1+json",
  "digest": "sha256:ee2e627348486cb8bd3cdbf19f1e8c03ffc55e10444fa165f8ce49d46400cd22",
  "size": 1609
},
"containerimage.digest": "sha256:ee2e627348486cb8bd3cdbf19f1e8c03ffc55e10444fa165f8ce49d46400cd22",
"image.name": "ghcr.io/graphql-hive/router:pr-638,ghcr.io/graphql-hive/router:sha-7d1c151"
}

@kamilkisiela kamilkisiela marked this pull request as ready for review January 7, 2026 13:04
@dotansimha dotansimha force-pushed the kamilkisiela-patch-1 branch from 8d0d7a8 to df7ce73 Compare January 11, 2026 16:06
Copy link
Member

@dotansimha dotansimha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, impossible to review :) but it makes perfect sense :)

@dotansimha
Copy link
Member

dotansimha commented Jan 11, 2026

also, i've added changeset and rebased

@dotansimha dotansimha requested a review from ardatan January 12, 2026 09:34
Added a buffer to the final response size estimate.
Updated the version of the sonic-simd package from 0.1.1 to 0.1.2 and added new dependencies.
Updated documentation link in json_writer.rs
@kamilkisiela kamilkisiela merged commit e709ec7 into main Jan 12, 2026
22 checks passed
@kamilkisiela kamilkisiela deleted the kamilkisiela-patch-1 branch January 12, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants